github.com/annchain/OG@v0.0.9/arefactor_core/core/(truncated) confirm_status.go (about) 1 // Copyright © 2019 Annchain Authors <EMAIL ADDRESS> 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 package core 15 16 //type ConfirmStatus struct { 17 // TxNum uint64 18 // ConfirmNum uint64 19 // Confirm time.Duration 20 // mu sync.RWMutex 21 // initTime time.Time 22 // RefreshTime time.Duration 23 //} 24 // 25 //type ConfirmInfo struct { 26 // ConfirmTime string `json:"confirm_time"` 27 // ConfirmRate string `json:"confirm_rate"` 28 //} 29 // 30 //func (c *ConfirmStatus) AddTxNum() { 31 // c.mu.Lock() 32 // defer c.mu.Unlock() 33 // if time.Since(c.initTime) > c.RefreshTime { 34 // c.TxNum = 0 35 // c.ConfirmNum = 0 36 // c.Confirm = time.Duration(0) 37 // c.initTime = time.Now() 38 // } 39 // c.TxNum++ 40 //} 41 // 42 //func (c *ConfirmStatus) AddConfirm(d time.Duration) { 43 // c.mu.Lock() 44 // defer c.mu.Unlock() 45 // 46 // c.Confirm += d 47 // c.ConfirmNum++ 48 //} 49 // 50 //func (c *ConfirmStatus) GetInfo() *ConfirmInfo { 51 // var info = &ConfirmInfo{} 52 // c.mu.RLock() 53 // defer c.mu.RUnlock() 54 // 55 // if c.TxNum != 0 { 56 // rate := float64(c.ConfirmNum*100) / float64(c.TxNum) 57 // if rate == 1 { 58 // info.ConfirmRate = "100%" 59 // } else if rate < 98 { 60 // info.ConfirmRate = fmt.Sprintf("%2d", int(rate)) + "%" 61 // } else { 62 // info.ConfirmRate = fmt.Sprintf("%3f", rate) + "%" 63 // } 64 // } 65 // if c.ConfirmNum != 0 { 66 // info.ConfirmTime = (c.Confirm / time.Duration(c.ConfirmNum)).String() 67 // } 68 // return info 69 //}